var a1, a2;
var library;
var stg;

function main(stage){
    var libraryLoader = new sp.Loader();
    var libraryURL = "anim.swf";
    var libraryURLRequest = new sp.URLRequest(libraryURL);
    libraryLoader.load(libraryURLRequest);
    libraryLoader.contentLoaderInfo.addEventListener(sp.Event.COMPLETE, libraryLoaded);

    function libraryLoaded(event)
    {
        library = libraryLoader.contentLoaderInfo.applicationDomain;
        Anim1 = library.getDefinition("anim1");
        Anim2 = library.getDefinition("anim2");
        a1 = new Anim1();
        stage.addChild( a1 );
        a2 = new Anim2();
        stage.addChild( a2 );

        Prog = library.getDefinition("progBar");
        progBar = new Prog();
        stage.addChild(progBar);
        progBar.x = 200;
        progBar.gotoAndStop(2);
        stg = stage;

        animInit();
    }
}

var Anim1, Anim2;


function onObjectClicked() {
    console.log("cliked");
}

function mouseMove() {
    console.log("moved");
}

function animInit() {
    console.log("loaded!");
    
    GreenRect = library.getDefinition("greenRect");
    gr1 = new GreenRect();
    gr1.y = 200;
    stg.addChild(gr1);

    gr1.addEventListener( sp.MouseEvent.MOUSE_DOWN, onObjectClicked );
    stg.addEventListener( sp.MouseEvent.MOUSE_MOVE, mouseMove );

    gr1.addEventListener( sp.TouchEvent.TOUCH_BEGIN, onObjectClicked );

    animLoop();
    console.log("initDone");

}

function animLoop() {
    a1.x += 10;
    if (a1.x > 500) {
        a1.x = 0;
    }
    setTimeout(animLoop, 500);
}





// Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT; 

// mc1 = new MovieClip(); 

/* 
 mc1.graphics.beginFill(0x336699); 
 mc1.graphics.drawRect(0,0,40,40); 
 // addChild(mySprite);   
 mySprite.addEventListener(TouchEvent.TOUCH_TAP, taphandler); 
 
 function taphandler(evt:TouchEvent): void { 
 myTextField.text = "I've been tapped"; 
 myTextField.y = 50; 
 addChild(myTextField); 
 }

 */

